package com.ruoyi.payOrder.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    //正常交换机的名称
    public static final String NORMAL_FANOUT_EXCHANGE = "normal_fanout_exchange";
    //死信交换机的名称
    public static final String DEATH_FANOUT_EXCHANGE = "death_fanout_exchange";

    //延迟队列名称
    public static final String DELAY_QUEUE = "delay_queue";
    //死信队列名称
    public static final String ORDER_STATUS_QUEUE = "order_status_queue";
    //死信队列名称
    public static final String COUPON_STATUS_QUEUE = "coupon_status_queue";
    //死信队列名称
    public static final String MESSAGE_QUEUE = "message_queue";


    //正常交换机
    @Bean
    public Exchange normalFanout() {
        return ExchangeBuilder.fanoutExchange(NORMAL_FANOUT_EXCHANGE).durable(true).build();
    }
    //死信交换机
    @Bean
    public Exchange deathFanout() {
        return ExchangeBuilder.fanoutExchange(DEATH_FANOUT_EXCHANGE).durable(true).build();
    }


    //延迟队列
    @Bean
    public Queue normalFanoutQueue() {
        return QueueBuilder.durable(DELAY_QUEUE).deadLetterExchange(DEATH_FANOUT_EXCHANGE).ttl(1000*60).maxLength(10).build();
    }
    //死信队列
    @Bean
    public Queue orderFanoutQueue() {
        return QueueBuilder.durable(ORDER_STATUS_QUEUE).build();
    }

    //死信队列
    @Bean
    public Queue couponFanoutQueue() {
        return QueueBuilder.durable(COUPON_STATUS_QUEUE).build();
    }

    //死信队列
    @Bean
    public Queue messageFanoutQueue() {
        return QueueBuilder.durable(MESSAGE_QUEUE).build();
    }


    //正常交换机绑定关系
    @Bean
    public Binding normalFanoutBinding() {
        return BindingBuilder.bind(normalFanoutQueue()).to(normalFanout()).with("").noargs();
    }
    //死信交换机的绑定关系
    @Bean
    public Binding orderFanoutBinding() {
        return BindingBuilder.bind(orderFanoutQueue()).to(deathFanout()).with("").noargs();
    }

    //死信交换机的绑定关系
    @Bean
    public Binding couponFanoutBinding() {
        return BindingBuilder.bind(couponFanoutQueue()).to(deathFanout()).with("").noargs();
    }

    //死信交换机的绑定关系
    @Bean
    public Binding messageFanoutBinding() {
        return BindingBuilder.bind(messageFanoutQueue()).to(deathFanout()).with("").noargs();
    }
}
